package com.zbkj.common.model.assistant;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 客服会话表
 * </p>
 *
 * @author keNan
 * @since 2025-06-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("eb_assistant_conversation")
@ApiModel(value="AssistantConversation对象", description="客服会话表")
public class AssistantConversation implements Serializable {

    private static final long serialVersionUID=1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "用户ID")
    private Integer userId;

    @ApiModelProperty(value = "用户昵称")
    private String userName;

    @ApiModelProperty(value = "用户头像")
    private String userAvatar;

    @ApiModelProperty(value = "当前接待客服ID")
    private Integer serviceAccountId;

    @ApiModelProperty(value = "客服昵称")
    private String serviceName;

    @ApiModelProperty(value = "客服头像")
    private String serviceAvatar;

    @ApiModelProperty(value = "最初接待客服ID")
    private Integer originalServiceAccountId;

    @ApiModelProperty(value = "全部接待客服ID，逗号分隔")
    private String allServiceAccountIds;

    @ApiModelProperty(value = "状态：0-等待接待，1-接待中，2-已结束")
    private Integer status;

    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    @ApiModelProperty(value = "结束类型0-未结束，1-客服结束，2-超时结束，3-禁用客服")
    private Integer endType;

    @ApiModelProperty(value = "评分")
    private Integer evaluationRating;

    @ApiModelProperty(value = "评价")
    private String evaluationComment;

    @ApiModelProperty(value = "评价时间")
    private Date evaluationTime;

    @ApiModelProperty(value = "用户发送消息数")
    private Integer userMsgCount;

    @ApiModelProperty(value = "客服发送消息数")
    private Integer serviceMsgCount;

    @ApiModelProperty(value = "会话转接次数")
    private Integer transferCount;

    @ApiModelProperty(value = "进入来源0-我的，1-商品，2-订单，3-售后单")
    private Integer source;

    @ApiModelProperty(value = "来源id")
    private String sourceId;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "客服首次回应时长")
    public Long getFirstReplySeconds() {
        if (ObjUtil.isNotEmpty(createTime) && ObjUtil.isNotEmpty(startTime)) {
            return (startTime.getTime() - createTime.getTime()) / 1000;
        }
        return null;
    }

    @ApiModelProperty(value = "客服平均回应时长")
    public Long getAvgReplySeconds() {
        if (ObjUtil.isNotEmpty(startTime) && ObjUtil.isNotEmpty(endTime) && ObjUtil.isNotEmpty(serviceMsgCount) && serviceMsgCount > 0) {
            Long seconds = (endTime.getTime() - startTime.getTime()) / 1000;
            return seconds / serviceMsgCount;
        }
        return null;
    }

    @ApiModelProperty(value = "会话时长")
    public Long getConversationSeconds() {
        if (ObjUtil.isNotEmpty(startTime) && ObjUtil.isNotEmpty(endTime)) {
            return (endTime.getTime() - startTime.getTime()) / 1000;
        }
        return null;
    }
}
